import {
	mapMutations
} from 'vuex'
export default {
	...mapMutations([
		'upUserInfo'
	]),
	getUserInfo() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/info',
			params: {
	
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if(res.data.sex == 1){
						that.select = '男'
						that.current = 0
						that.pickerValue =0
					}else{
						that.select = '女'
						that.current = 1
						that.pickerValue = 1
					}
					
					
					that.upUserInfo(res.data)
				} else {
					that.upUserInfo({})
				}
			}
		})
	},
	upAvatar() {
		let that = this
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				let avatar = res.data.filePath
				that.$httpRequest.request({
					that: that,
					url: 'h5/editAvatar',
					params:{
						avatar:res.data.id
					},
					success: res => {
						that.$toast.alert({
							content: res.message,
							callback: result => {
				
							}
						})
						if (res.code === that.$httpConfig.SUCCESS_CODE) {
							that.userInfo.avatarPath = avatar
							that.upUserInfo(that.userInfo)
						} else {
				
						}
					}
				})
			}
		})
	},
	//修改用户性别
	editSex() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'h5/editSex',
			params: {
				sex:parseInt(that.current+1) 
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					// that.upUserInfo(res.data)
				} else {
					// that.upUserInfo({})
				}
			}
		})
	},
	getSex(e){
		
		var obj = this.sexList[e.detail.value]
		console.log(obj)
		this.select = obj['label']
		let number = parseInt(e.detail.value)
		this.current = number >= 0 ? number : 0
		this.editSex()
	},
	toEditNickname() {
		let that = this
		if (that.atLoading) {
			//禁止多次点击
			return false
		}
		that.atLoading = true
		uni.navigateTo({
			url: '/pages/my/editNickname'
		})
		setTimeout(()=>{ //延时指定时间后，再解冻
			that.atLoading = false;
		}, 1000);
		
	},

}
